package controls
{
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;
  import spark.components.TextInput;

  /**
   * ...
   * @author Roman Marchenko
   */
  public class TextInputSimple extends spark.components.TextInput
  {

    private var ssi:int = 0;
    private var sei:int = 0;

    public function TextInputSimple()
    {
      super();
      this.addEventListener(KeyboardEvent.KEY_DOWN, onBeforeKeyDown, false, 10000);
      this.addEventListener(KeyboardEvent.KEY_DOWN, onAfterKeyDown, false, -10000);
    }

    private function onBeforeKeyDown(e:KeyboardEvent):void
    {
      if (e.keyCode == Keyboard.UP || e.keyCode == Keyboard.DOWN)
      {
        ssi = this.selectionAnchorPosition;
        sei = this.selectionActivePosition;
      }
    }

    private function onAfterKeyDown(e:KeyboardEvent):void
    {
      if (e.keyCode == Keyboard.UP || e.keyCode == Keyboard.DOWN)
      {
        this.selectRange(ssi, sei);
      }
    }
  }

}